import { Component, defineComponent } from "vue";

const keepPage = new Map();
export const createCustomComponent = (customName: string, asyncComponent: Component) => {
  if (keepPage.has(customName)) {
    return keepPage.get(customName);
  } else {
    const page = defineComponent({
      name: customName,
      components: {
        AsyncComponent: asyncComponent
      },
      setup() {
        return () => <AsyncComponent />;
      }
    });
    keepPage.set(customName, page);
    return page;
  }
};

export const clear = () => {
  keepPage.clear();
};
